﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace JQData.Database.Migrations.Migrations
{
    /// <inheritdoc />
    public partial class v106 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<string>(
                name: "Orgs",
                table: "HotMoney",
                type: "varchar(2000)",
                maxLength: 2000,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "varchar(500)",
                oldMaxLength: 500,
                oldNullable: true)
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "HotMoneyStockCycleProfit",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    HotMoneyId = table.Column<int>(type: "int", nullable: false),
                    StockId = table.Column<int>(type: "int", nullable: false),
                    BuyVol = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    SellVol = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    BuyAmount = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    SellAmount = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    Profit = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    IsWin = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    HoldingDays = table.Column<int>(type: "int", nullable: false),
                    SourceBuyTradeIds = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SourceSellTradeIds = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    StartDate = table.Column<DateOnly>(type: "date", nullable: false),
                    EndDate = table.Column<DateOnly>(type: "date", nullable: true),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: false),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_HotMoneyStockCycleProfit", x => x.Id);
                    table.ForeignKey(
                        name: "FK_HotMoneyStockCycleProfit_HotMoney_HotMoneyId",
                        column: x => x.HotMoneyId,
                        principalTable: "HotMoney",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_HotMoneyStockCycleProfit_StockBasic_StockId",
                        column: x => x.StockId,
                        principalTable: "StockBasic",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_HotMoneyStockCycleProfit_HotMoneyId",
                table: "HotMoneyStockCycleProfit",
                column: "HotMoneyId");

            migrationBuilder.CreateIndex(
                name: "IX_HotMoneyStockCycleProfit_StockId",
                table: "HotMoneyStockCycleProfit",
                column: "StockId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "HotMoneyStockCycleProfit");

            migrationBuilder.AlterColumn<string>(
                name: "Orgs",
                table: "HotMoney",
                type: "varchar(500)",
                maxLength: 500,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "varchar(2000)",
                oldMaxLength: 2000,
                oldNullable: true)
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");
        }
    }
}
